﻿using System;

namespace Jlvier.TaobaoShowcase.Service
{
    internal class KeyTime
    {
        private const int DefaultMinute = 0;
        private const int DefaultSecond = 0;
        private readonly int minute;
        private readonly int second;
        private readonly int hour;

        public KeyTime(int hour)
            :this(hour,DefaultMinute,DefaultSecond)
        {
        }
        public KeyTime(int hour,int minute,int second)
        {
            this.hour = hour;
            this.minute = minute;
            this.second = second;
        }

        public int Hour
        {
            get { return hour; }
        }
        public int Minute
        {
            get { return minute; }
        }
        public int Second
        {
            get { return second; }
        }

        public static bool operator >=(KeyTime a,KeyTime b)
        {
            if (a.Hour > b.Hour) return true;
            if (a.Hour < b.Hour) return false;
            if (a.Hour == b.Hour)
            {
                if (a.Minute > b.Minute) return true;
                if (a.Minute < b.Minute) return false;
                if (a.Minute == b.Minute)
                {
                    if (a.Second >= b.Second) return true;
                    if (a.Second < b.Second) return false;
                }
            }
            throw new NotImplementedException();
        }
        public static bool operator <=(KeyTime a, KeyTime b)
        {
            if (a.Equals(b)) return true;
            return a >= b;
        }

        public override bool Equals(object obj)
        {
            var another = obj as KeyTime;
            if (null == another) return false;
            return Hour == another.Hour && Minute == another.Minute && Second == another.Second;
        }
    }
}